package com.eascs.web.o2o.web.controller;

import java.text.DecimalFormat;
import java.text.Format;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.o2o.web.form.BadStatmentForm;
import com.eascs.web.o2o.web.service.BadStatmentService;
import com.eascs.web.o2o.web.service.ProvinceNameData;

@RestController
@RequestMapping("/restBadStatment")
public class BadStatmentRestController  extends BaseRestController {

	@Autowired
	BadStatmentService badStatmentService;

	@Autowired
	ProvinceNameData provinceNameData;
	
	
	
	@RequestMapping("/bsr_list")
	public PaginationRestResult  badStatmentList(BadStatmentForm vo){
		String o2ourl = "/restBadStatment/bsr_list";
		if(vo != null){
			String endDate = vo.getEndDate() == null ? "" : vo.getEndDate();
			String province = vo.getProvince() == null ? "" : vo.getProvince();
			o2ourl = UrlUtil.appendUrl(o2ourl, "endDate", endDate);
			o2ourl = UrlUtil.appendUrl(o2ourl, "province", province);
			o2ourl = o2ourl + "&pageIndex=";
		}else{
			o2ourl = o2ourl + "?pageIndex=";
		}
		vo.setPageSize(10);
		PageResult<Object[]> result = badStatmentService.BadStatmentList(vo);
		String titles[] = {"省区","逾期笔数","逾期余额","代偿笔数","代偿金额","到期笔数","到期金额","逾期笔数/到期笔数","本月代偿的回款率","历史代偿在本月的回款金额","本月代偿的回款金额","所有代偿的催收率"};
		PaginationInfo paginationInfo = new PaginationInfo(result, titles, o2ourl);
 		SelectDataOption[] selectDataOptions = { null,null,null, null, null, null, null, null, null, null, null, null};
 		paginationInfo.setBuildPagingNavigation(true);
 		paginationInfo.setFirstRenderColumnIndex(0);
 	    paginationInfo.setSelectDataOptions(selectDataOptions);
 		paginationInfo.setFormats(new Format[] { null, null, null, null, null ,null,null, null, null ,null,null, null});
 		paginationInfo.setRendTo("#o2o_bad_statment");
 		ViewContext.put("vo", vo);
		ViewContext.put("paginationInfo", paginationInfo);
 		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
 	}
	
	
}
